// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsElementMessage.
//   $Id$


#pragma once
#include "parseMessage.h"
#include "ActionMessage.h"
#include "ElementWithXBL.h"
#include "xformselementdefaultimpl.h"
#define CXFORMSELEMENTMESSAGE_EVENTS_LENGTH 2
interface IEngine;

class CXFormsElementMessage:
		public CXFormsElementDefaultListenerImpl<CXFormsElementDefaultImpl<CImplActionMessage,CXFormsParseMessage,CXFormsElementMessage,CElementWithXBL> >
{
public:
	
	BEGIN_COM_MAP(CXFormsElementMessage)
		COM_INTERFACE_ENTRY(IEventListener)
		COM_INTERFACE_ENTRY_CHAIN(CXFormsElement)
	END_COM_MAP()
#ifdef _DEBUG
	ULONG InternalAddRef()
	{
		return __super::InternalAddRef();
	}
	ULONG InternalRelease()
	{
		return __super::InternalRelease();
	}
#endif
	CXFormsElementMessage(void);
	virtual ~CXFormsElementMessage(void);
	STDMETHOD(Detach)();
	virtual HRESULT put_value(BSTR sValue);
	virtual HRESULT InitBehaviour();
	virtual HRESULT DocumentReady();

	HRESULT InsertBranding(void) {/* REMOVE BRANDING */ return S_OK; };
	//virtual HRESULT ElementReady(void);
	
	STDMETHOD(handleEvent)(IDOMEvent * pEvent);

protected:
	virtual HRESULT render(void);

private:
	void rebrand(void);
	CComPtr<IHTMLImgElement> m_pBrandingImage;
	CComPtr<IEngine> m_pEngine;
	bool m_bDeferredBranding;

	//<summary>
	//	array storing event cookies.
	//	these are the ids given to us by 
	//	RegisterEvent.
	//</summary>
	long m_alEventCookies[CXFORMSELEMENTMESSAGE_EVENTS_LENGTH];
	//<summary>
	//The event cookies are assigned on an
	//	object-by-object basis, however, 
	//	the names can be static.
	//</summary>
	static const CComBSTR * const sm_asEventNames[CXFORMSELEMENTMESSAGE_EVENTS_LENGTH];
	bool m_bUseDialog;
	CComBSTR m_sValue;

};